<?php
	class Mysql{
		private $link;
		private $host;
		private $root;
		private $pwd;
		private $dbname;
		private $charset;
		public static $instance;
		private function __construct($config){
			$this->host = isset($config['host'])?$config['host']:'127.0.0.1';
			$this->root = isset($config['root'])?$config['root']:'root';
			$this->pwd = isset($config['pwd'])?$config['pwd']:'root';
			$this->dbname = isset($config['dbname'])?$config['dbname']:'mysql';
			$this->charset = isset($config['charset'])?$config['charset']:'utf8';
			$this->connectDB();
		}
		private function __clone(){

		}
		public static function Instance($config){
			if(!self::$instance){
				self::$instance = new self($config);
			}
			return self::$instance;
		}
		private function connectDB(){
			$this->link = mysqli_connect($this->host,$this->root,$this->pwd);
			if(!$this->link){
				echo mysqli_connect_error();
				exit;
			}
			mysqli_set_charset($this->link,$this->charset);
			mysqli_select_db($this->link,$this->dbname);
		}
		public function selectDB($sql){
			$data = mysqli_query($this->link,$sql);
			$datas = [];
			while($row = mysqli_fetch_assoc($data)){
				$datas[] = $row;
			}
			return $datas;
		}
		public function selectRows($sql){
			$data = mysqli_query($this->link,$sql);
			$row = mysqli_num_rows($data);
			return $row;
		}
		public function query($sql){
			$data = mysqli_query($this->link,$sql);
			return $data;
		}
	}